<template>
  <view class="userLayout pageBg">
    <view :style="{height:getNavBarHeight()+ 'px'}"></view>
    <view class="userInfo">
      <view class="avatar">
        <image src="/common/xxmLogo.png" mode="aspectFill"></image>
      </view>
      <view class="ip">
        {{userInfo.IP}}
      </view>
      <view class="address">
        来自于：{{userInfo?.address?.province}} - {{userInfo?.address?.city}}
      </view>
      <!-- <button open-type="contcat">联系客服</button> -->
    </view>
    <view class="section">
      <view class="list">
          <view class="row" @click="goToSomePage(item.navigateTo)" v-for="item in listData1" :key="item">
            <view class="left">
              <uni-icons :type="item.icon" size="20"></uni-icons>
              <view class="text">{{item.text}}</view>
              <!-- #ifdef MP -->
              <button v-if="item.button" open-type="contact">联系客服</button>
              <!-- #endif -->
              <!-- #ifndef MP -->
              <button v-if="item.button" @click="clickContact">拨打电话</button>
              <!-- #endif -->
            </view>
            <view class="right">
              <view class="text">{{item.num}}</view>
              <uni-icons type="right" size="15" color="#aaa"></uni-icons>
            </view>
          </view>
      </view>
    </view>
    <view class="section">
      <view class="list">
        <view class="row" v-for="item in listData2" :key="item">
          <view class="left">
            <uni-icons :type="item.icon" size="20"></uni-icons>
            <view class="text">{{item.text}}</view>

          </view>
          <view class="right">
            <!-- <view class="text">33</view> -->
            <uni-icons type="right" size="15" color="#aaa"></uni-icons>
          </view>
        </view>
      </view>
    </view>
  </view>
  <!-- <navigator url="/pages/classlist/classlist"></navigator> -->
</template>

<script setup>
import { getNavBarHeight } from "@/utils/system.js"
import { apiUserInfo } from "@/api/apis.js"
import { ref } from 'vue'
import { onLoad } from "@dcloudio/uni-app"
console.log('安全区域',getNavBarHeight());
const userInfo = ref({})
const getUserInfo = () =>{
  console.log('ok');
  apiUserInfo().then(res=>{
    console.log(res.data);
    userInfo.value = res.data
    listData1.value[0].num = res.data.downloadSize
    listData1.value[1].num = res.data.scoreSize
  })
}
onLoad(()=>{
  getUserInfo()
})

const listData1 = ref([
  {
    icon: 'download-filled',
    text:'我的下载',
    num:33,
    navigateTo:'/pages/classlist/classlist'
  },
  {
    icon: 'star-filled',
    text:'我的评分',
    num:2,
    navigateTo:'/pages/classlist/classlist'
  },
  {
    icon: 'chatboxes-filled',
    text:'联系客服',
    num:0,
    button:true,
  }
])
const listData2 = [
  {
    icon: 'upload',
    text:'订阅更新',
    navigateTo:'/pages/classlist/classlist'
  },
  {
    icon: 'flag-filled',
    text:'常见问题',
    navigateTo:'/pages/classlist/classlist'
  }
]

const clickContact = () =>{
  uni.makePhoneCall({
    phoneNumber:"114"
  })
}

const goToSomePage = (url="/pages/user/user") =>{
  uni.navigateTo({
    url:url
  })
}
</script>

<style lang="scss">
.userLayout {
  .userInfo {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 50rpx 0;
    .avatar {
      width: 160rpx;
      height: 160rpx;
      border-radius: 50%;
      overflow: hidden;
      image {
        width: 100%;
        height: 100%;
      }
    }
    .ip {
      font-size: 44rpx;
      color: #333;
      padding: 20rpx 0 5rpx;
    }
    .address {
      font-size: 28rpx;
      color: #aaa;
    }
  }
  .section {
    width: 690rpx;
    margin: 50rpx auto;
    border: 1px solid #eee;
    border-radius: 10rpx;
    box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);
    .list {
      .row {
        background-color: #fff;
        position: relative;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 30rpx;
        height: 100rpx;
        border-bottom: 1px solid #eee;
        &:last-child{border-bottom: 0;}
        .left {
          display: flex;
          align-items: center;
          :deep() {
            .uni-icons {
              color: $brand-theme-color !important;
            }
          }
          .uni-icons {
            color: $brand-theme-color !important;
          }
          .text {
            padding-left: 20rpx;
            color: #666;
          }
        }
        .right {
          display: flex;
          align-items: center;
          .text {
            font-size: 28rpx;
            color: #aaa;
          }
        }
        button {
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: 100%;
          opacity: 0;
        }
      }
    }
  }
}
</style>
